# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Contributor: John Regan <john@jrjrtech.com>
# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ejabberd
pkgver=24.10
pkgrel=0

_base64url=1.0.1
_cache_tab=1.0.31
_eimp=1.0.23
_ejabberd_po=64a22cf1a2be98aed6303da0e5c9e09b18043786
_epam=1.0.14
_eredis=1.2.0
_esip=1.0.56
_ezlib=1.0.13
_fast_tls=1.1.22
_fast_xml=1.1.53
_fast_yaml=1.0.37
_idna=6.1.1
_jiffy=1.1.2
_jose=1.11.10
_luerl=1.2
_mqtree=1.0.17
_p1_acme=1.0.24
_p1_mysql=1.0.25
_p1_oauth2=0.6.14
_p1_pgsql=1.1.28
_p1_utils=1.0.26
_pkix=1.0.10
_sqlite3=1.1.15
_stringprep=1.0.30
_stun=1.2.15
_unicode_util_compat=0.7.0
_xmpp=1.9.0
_yconf=1.0.16

pkgdesc="An erlang jabber server"
url="https://www.ejabberd.im/"
arch="all"
license="GPL-2.0-or-later"
depends="
	erlang
	elixir
	"
makedepends="
	autoconf
	automake
	erlang-dev
	expat-dev
	gd-dev
	heimdal-dev
	linux-pam-dev
	openssl-dev>3
	rebar3
	sqlite-dev
	yaml-dev
	zlib-dev
	"
pkgusers="ejabberd"
pkggroups="ejabberd"
install="$pkgname.pre-install"
options="!check" # test suite requires all kinds of services running
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/processone/ejabberd/archive/$pkgver.tar.gz
	base64url-$_base64url.tar.gz::https://github.com/dvv/base64url/archive/refs/tags/$_base64url.tar.gz
	cache_tab-$_cache_tab.tar.gz::https://github.com/processone/cache_tab/archive/refs/tags/$_cache_tab.tar.gz
	eimp-$_eimp.tar.gz::https://github.com/processone/eimp/archive/refs/tags/$_eimp.tar.gz
	ejabberd_po-$_ejabberd_po.tar.gz::https://github.com/processone/ejabberd-po/archive/$_ejabberd_po.tar.gz
	epam-$_epam.tar.gz::https://github.com/processone/epam/archive/refs/tags/$_epam.tar.gz
	eredis-$_eredis.tar.gz::https://github.com/wooga/eredis/archive/refs/tags/v$_eredis.tar.gz
	esip-$_esip.tar.gz::https://github.com/processone/esip/archive/refs/tags/$_esip.tar.gz
	ezlib-$_ezlib.tar.gz::https://github.com/processone/ezlib/archive/refs/tags/$_ezlib.tar.gz
	fast_tls-$_fast_tls.tar.gz::https://github.com/processone/fast_tls/archive/refs/tags/$_fast_tls.tar.gz
	fast_xml-$_fast_xml.tar.gz::https://github.com/processone/fast_xml/archive/refs/tags/$_fast_xml.tar.gz
	fast_yaml-$_fast_yaml.tar.gz::https://github.com/processone/fast_yaml/archive/refs/tags/$_fast_yaml.tar.gz
	idna-$_idna.tar.gz::https://github.com/benoitc/erlang-idna/archive/refs/tags/$_idna.tar.gz
	jiffy-$_jiffy.tar.gz::https://github.com/davisp/jiffy/archive/refs/tags/$_jiffy.tar.gz
	jose-$_jose.tar.gz::https://github.com/potatosalad/erlang-jose/archive/refs/tags/$_jose.tar.gz
	luerl-$_luerl.tar.gz::https://github.com/rvirding/luerl/archive/refs/tags/v$_luerl.tar.gz
	mqtree-$_mqtree.tar.gz::https://github.com/processone/mqtree/archive/refs/tags/$_mqtree.tar.gz
	p1_acme-$_p1_acme.tar.gz::https://github.com/processone/p1_acme/archive/refs/tags/$_p1_acme.tar.gz
	p1_mysql-$_p1_mysql.tar.gz::https://github.com/processone/p1_mysql/archive/refs/tags/$_p1_mysql.tar.gz
	p1_oauth2-$_p1_oauth2.tar.gz::https://github.com/processone/p1_oauth2/archive/refs/tags/$_p1_oauth2.tar.gz
	p1_pgsql-$_p1_pgsql.tar.gz::https://github.com/processone/p1_pgsql/archive/refs/tags/$_p1_pgsql.tar.gz
	p1_utils-$_p1_utils.tar.gz::https://github.com/processone/p1_utils/archive/refs/tags/$_p1_utils.tar.gz
	pkix-$_pkix.tar.gz::https://github.com/processone/pkix/archive/refs/tags/$_pkix.tar.gz
	sqlite3-$_sqlite3.tar.gz::https://github.com/processone/erlang-sqlite3/archive/refs/tags/$_sqlite3.tar.gz
	stringprep-$_stringprep.tar.gz::https://github.com/processone/stringprep/archive/refs/tags/$_stringprep.tar.gz
	stun-$_stun.tar.gz::https://github.com/processone/stun/archive/refs/tags/$_stun.tar.gz
	unicode_util_compat-$_unicode_util_compat.tar.gz::https://github.com/benoitc/unicode_util_compat/archive/refs/tags/$_unicode_util_compat.tar.gz
	xmpp-$_xmpp.tar.gz::https://github.com/processone/xmpp/archive/refs/tags/$_xmpp.tar.gz
	yconf-$_yconf.tar.gz::https://github.com/processone/yconf/archive/refs/tags/$_yconf.tar.gz

	$pkgname.initd
	$pkgname.logrotate
	$pkgname.confd

	jiffy-double-conversion-loongarch64.patch
	"

export HEX_HOME="${HEX_HOME:-"$srcdir/hex"}"
export MIX_HOME="${MIX_HOME:-"$srcdir/mix"}"
export MIX_ARCHIVES="${MIX_ARCHIVES:-"$srcdir/mix/archives"}"

prepare() {
	mkdir -vp _build/default/lib
	for i in \
	base64url-$_base64url \
	cache_tab-$_cache_tab \
	eimp-$_eimp \
	epam-$_epam \
	eredis-$_eredis \
	esip-$_esip \
	ezlib-$_ezlib \
	fast_tls-$_fast_tls \
	fast_xml-$_fast_xml \
	fast_yaml-$_fast_yaml \
	jiffy-$_jiffy \
	luerl-$_luerl \
	mqtree-$_mqtree \
	p1_acme-$_p1_acme \
	p1_mysql-$_p1_mysql \
	p1_oauth2-$_p1_oauth2 \
	p1_pgsql-$_p1_pgsql \
	p1_utils-$_p1_utils \
	pkix-$_pkix \
	stringprep-$_stringprep \
	stun-$_stun \
	unicode_util_compat-$_unicode_util_compat \
	xmpp-$_xmpp \
	yconf-$_yconf; do
		mv -v "$srcdir"/"$i" "$builddir"/_build/default/lib/${i%-*}
	done
	mv -v "$srcdir"/ejabberd-po-$_ejabberd_po "$builddir"/_build/default/lib/ejabberd_po
	mv -v "$srcdir"/erlang-sqlite3-$_sqlite3 "$builddir"/_build/default/lib/sqlite3
	mv -v "$srcdir"/erlang-idna-$_idna "$builddir"/_build/default/lib/idna
	mv -v "$srcdir"/erlang-jose-$_jose  "$builddir"/_build/default/lib/jose

	mix local.hex --force
	mix local.rebar --force rebar3 /usr/bin/rebar3

	default_prepare
	GIT_DIR=. sh ./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--sbindir=/usr/sbin \
		--libdir=/usr/lib/ejabberd \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-rebar=rebar3 \
		--disable-tools \
		--enable-user=ejabberd \
		--enable-group=ejabberd \
		--enable-all
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 tools/captcha* \
		-t "$pkgdir"/usr/share/doc/$pkgname/examples
	install -Dm644 tools/ejabberdctl.bc \
		"$pkgdir"/usr/share/bash-completion/completions/ejabberdctl

	install -d "$pkgdir"/var/spool/$pkgname
	install -d "$pkgdir"/var/lib/$pkgname
	install -D -m0644 "$srcdir"/$pkgname.logrotate \
		"$pkgdir"/etc/logrotate.d/$pkgname
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	chown -R ejabberd:ejabberd "$pkgdir"/var/log/ejabberd
	chown -R ejabberd:ejabberd "$pkgdir"/var/spool/ejabberd
	chown -R ejabberd:ejabberd "$pkgdir"/var/lib/ejabberd
	chgrp ejabberd "$pkgdir"/etc/ejabberd/ejabberd.yml \
		"$pkgdir"/etc/ejabberd/ejabberdctl.cfg "$pkgdir"/etc/ejabberd

	cd "$pkgdir"/usr/lib/ejabberd/ejabberd-$pkgver/priv/bin/
	rm -vf captcha.sh
	ln -vsf ../../../*/priv/bin/* .
}

sha512sums="
dc32e341d5a5cf0c02574b14059ed95feaa8d840080a7c9367186b9a076ab0124df5b54b522732cd9541ed53140cff4024abe8353e91af18abd3c76d69fe9e19  ejabberd-24.10.tar.gz
7398dc99078053b6e0544eb8ca93e9616549493c02245084c220ec854f429139dcaba38dd522858dd74b95067979a3ec4378eb3abd5f6d1662af27687381c738  base64url-1.0.1.tar.gz
311f9debacf2c7f8ffecefb4fec4aaba254bd4d92b9ea10fa2c51bef9ce49953b60c7427dc207dff3ff85085bbed18b00eb56937836d943e4fe1dc30f3ca9b2c  cache_tab-1.0.31.tar.gz
220e7c6e253525989378de7d6f930679b28b6b30b498ff4f08c2b7a220c5d69cf95d929da9330ace589cf8cb26317d1ecc605bab8fcf2a0e13b49bca879d65bd  eimp-1.0.23.tar.gz
d7ea3ab4116fe4eedead534166ee865befddca0302e184d5a00cc27c1b3cef6347a4fdd64aec8a8fc1184718a29e983082b4eb1b8cae8e85ae04ede11559f578  ejabberd_po-64a22cf1a2be98aed6303da0e5c9e09b18043786.tar.gz
a8ff1e6095ad6f2cdf8a9766a7d846377e6ac5659851078a67a80595710fbd1552f900f0b4cad0baa54d63d3fbbe6009371f3a51dcaffe95c17565c0f7177678  epam-1.0.14.tar.gz
c72ae291389e47d1ac4c1de69dccb6121f4f9195283665d490904226b2ea15cb7671b48bb08db507a5e62c6bced62d890a9ecb9752da6e0aad24a28da137907c  eredis-1.2.0.tar.gz
8cfa69ca157dfd483851f707ca647bf9a5deac668d5fcc02641960d27684a352f2b967472ed5e527a9940442c3967980924de5d1e3cfe50f60ecd4ab73348fa3  esip-1.0.56.tar.gz
947594a219c71a9afb792dc7766712694159cf7ed24df37c646ebbe8b366f82035067cb75ba00d7b9364e1ffc438090c54a93f41f67a57167c8ec4ab8f1ae663  ezlib-1.0.13.tar.gz
62a213f2cfdf57b3d3995d11da5e21527fd29518bdcad61b3779e7c59bc2e232aa156288d386463f07b5e4f6a54f65f3f53df69133325c9710b9472088938a72  fast_tls-1.1.22.tar.gz
fe19c2c2b877b2936cf48f1c28b692f92329dc298d26d5bd25a37656a531736a213abd90d18f5546dc488cf389afde8384c7551c97fe81c48646a361b6f6edc0  fast_xml-1.1.53.tar.gz
26ff0d5bc8b0c4a4b45102dde42c2e372163220afbc523bf17fb9e7edf306f40c17883c60a4ad10417ff01731456dab94093cdc96196e10d2629c9ed05e84c2f  fast_yaml-1.0.37.tar.gz
aa1c4321e1925c8eb6b9cbab61c0216ed2837027382a1a0c36de10959a428a52443f225f901d64740f8b8b3d755990651fa74594d13b36e4131a5d0223a58608  idna-6.1.1.tar.gz
4f04246f6de11535ce8c5e1361646a7526d12944a08e9a496f5fe8ae8ef3d4afc4524b3ccb5fb5832ebf18fc8acae3283de377986f9bc8dd70e55a9eae7e45ab  jiffy-1.1.2.tar.gz
cddf868c360126a01727c19ac8bb4de3a0ebba191f84b6907da72666e1d29abaccfa2717527f8ec633c711e84771805b0ec1ad5f5b8f33df16ac2622e4b8e35d  jose-1.11.10.tar.gz
1d549641f41bc3e920d8c3a5594b4076b1fd085cd037e6fe10cacca9b7c0007675e8570272882909a88c045cbcffde4bd5ebb6bd76970e9d4e652ffe5da88a14  luerl-1.2.tar.gz
9d4ab0bc3b5cf8604b2260dd2ba8e1ba8a64530e6d6f7811bf72ae6934dd1164f3fbae52ce32bf97951d9b8f2679d2ca3715381ef24b8c02c6290c3d2a0e49d0  mqtree-1.0.17.tar.gz
fb9ed293767da4fa0871d241f9c7935da108dd8bc13204241ba8865597841156156872cd9809831ad9b0218ece1aa36c8f54f3d5cfa12c536cf65c60ce9790c2  p1_acme-1.0.24.tar.gz
266e7f0492397e1cc0abef64e40173719dd93118f79eb628dae5661a60069356d318bb22661900aa00e0331fe53890c266fb61082d24c4cbeba4c2326cef883b  p1_mysql-1.0.25.tar.gz
cda660e2401a951864d365017f508c2e317794a7aec7ee3aae96d476764252b56de516b31ca73da00c4a9ceefeefe22d673b4659e988179aeb9bb3eef0bf66ed  p1_oauth2-0.6.14.tar.gz
8991532d6425c86a9f60c4b025d49a31ae8f262098d49653c8eb0352a6755d7e4c4a55afaa13539982b633fc8549e1e0b504b8e37143fc93573b45946cf2d2b4  p1_pgsql-1.1.28.tar.gz
2e17a931302ac6c6c560b92a38f6868f3e2c5863fa9a3724ed7f3339ce149c7be1b8202cafebb26edbf547dfa49a62cae9c4016dd0b0f3aa5bc3d3d918324519  p1_utils-1.0.26.tar.gz
955308820b49d8f2ae155ad4b60704aca0706bbf0ced759c7a47b8e34c585a326eb7f29495174c8599054311414acd3de48fc03b7f5f9a669eb7956e76f36581  pkix-1.0.10.tar.gz
d055bd622c213f0dc8d6fa5ee50eab52e4aae264a9d59ea6e24f305d4a1388be9c1494b02a3e02ada3b3158bc594f9e912dfb1646c4518c8007e378d903355f1  sqlite3-1.1.15.tar.gz
cecf7d19b27b3dd8990bd546b0e8eb8cdae38c3e859b8f6e8dc54ae6c0bff711ec442623432cba9b85aa8dda5634bd6ef837876fef40c990c2c1a7aac9a22d48  stringprep-1.0.30.tar.gz
2a304166891f0a34299ce7ca883a2f402e78e48a68329da74e150f205aa629b4be3a0cedf58e45a28e939a7bfe97705680491efb44d70a14c92d2f397d1ff758  stun-1.2.15.tar.gz
de382c9f0af745d1565c90750a22aa42ba4ee6551606ac9ac92e7e93b8317a23d77f1d57e2c74911febb94ceda38ba19d7ac863c754aff97abee64a6307818d0  unicode_util_compat-0.7.0.tar.gz
19005703c6b4d3f1bc8e411632a16417261e9dff5a31787faad9fbc323ac9dc034d4bc03a76f0b4fb6d51d1f96593286710a6f998bce732deac39e207dcbb1b2  xmpp-1.9.0.tar.gz
e1d51444c21e2f6f16d0a20f8bd7d09d70a2eb087048e22b8e442dfcd8d15de0cf0af4c99f3c0a1b6f87b4d027363adf5cc98ec4fd7d1b9afdcfa8fca792f8af  yconf-1.0.16.tar.gz
18fb890794be6b0e63960af80a39a97b8c70a6c0ab9a91a95d0f623257e38f5a43c012430ccf871038fc440d06720c573821b485a94191bd73e3924e670683c5  ejabberd.initd
47fd2cfd9177c4e978a9799a153ba74392a9891822221af8194686a40f6bf01f38644833e1e1f5416c6357e0bfb7ca3dae96f55a4fcd7cd629ec798d85a72807  ejabberd.logrotate
96a571c0ab2be366e931bda423a61ef920cbaba2107e61ddbc501472ce3efe2804418cc6579c99310b902a9a99aaecb9284cf2420c071dbca2f670efb4034135  ejabberd.confd
60cc50b74d94f3c55f8fd76c345eadd34977460b0bd4a43701373324acc10850aa21d51edc74155aaf402915f7f5cf4ddd0d024bf45797f2d0e1a889dd77f36d  jiffy-double-conversion-loongarch64.patch
"
